package service

import (
	"project/model"
)

type CustomerService struct {
	customers []model.Customer
	// 声明一个字段，表示当前切片含有多少个客户
	// 该字段后面还可以作为新客户 id+1
	customerNum int
}

// 编写一个方法，可以返回*CustomerService
func NewCustomerService() *CustomerService {
	// 为了能够看到有客户在切片中，我们初始化一个客户
	customerService := &CustomerService{}
	customerService.customerNum = 1
	customer := model.NewCustomerService(1, "张三", "男", 18, "13792392", "1@qq.com")
	customerService.customers = append(customerService.customers, customer)
	return customerService
}

// 返回客户切片
func (this *CustomerService) List() []model.Customer {
	return this.customers
}

// 添加客户到customers切片
func (this *CustomerService) Add(customer Customer) bool {
	// 需要确定分配Id的规则，就是添加的顺序
	this.customerNum++
	customer.Id = this.customerNum
	this.customers = append(this.customers, customer)
	return true
}